package com.cntv.viewmodeldemo.fragment

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel


/**
 * author    : mahongyin
 * e-mail    : mhy.work@foxmail.com
 * date      : 2020-09-20 11:02
 * introduce :
 */
class UserModel : ViewModel() {
    private var mAccount = MutableLiveData<UserBean>()

    fun setUser(name: String, phone: String, address: String) {
        mAccount.setValue(UserBean(name, phone, address))
    }

    fun getUser(): MutableLiveData<UserBean>? {
        return mAccount
    }

    // 当MyActivity被销毁时，Framework会调用ViewModel的onCleared()
    override fun onCleared() {
        Log.i("mhyLog", "==========onCleared()==========")
        super.onCleared()
    }
companion object{
//    @JvmStatic //如果使用注解 将变成真正的相对于java的静态函数
    fun getFormatContent(name: String?, phone: String?, address: String?): String? {
        val mBuilder = StringBuilder()
        mBuilder.append("昵称:")
        mBuilder.append(name)
        mBuilder.append("\n手机:")
        mBuilder.append(phone)
        mBuilder.append("\n地址:")
        mBuilder.append(address)
        return mBuilder.toString()
    }}
}